using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class CategoryTypesDAO
	{
		public CategoryTypesDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<CategoryTypes> GetCategoryTypess()
		{
			try
			{
				List<CategoryTypes> lstCategoryTypess = new List<CategoryTypes>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTCategoryTypess",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					CategoryTypes oCategoryTypes = new CategoryTypes();
					oCategoryTypes.Id = Convert.ToInt32(oDbDataReader["Id"]);
					oCategoryTypes.Title = Convert.ToString(oDbDataReader["Title"]);
					lstCategoryTypess.Add(oCategoryTypes);
				}
				oDbDataReader.Close();
				return lstCategoryTypess;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public CategoryTypes GetCategoryTypes(int Id)
		{
			try
			{
				CategoryTypes oCategoryTypes = new CategoryTypes();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTCategoryTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oCategoryTypes.Id = Convert.ToInt32(oDbDataReader["Id"]);
					oCategoryTypes.Title = Convert.ToString(oDbDataReader["Title"]);
				}
				oDbDataReader.Close();
				return oCategoryTypes;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddCategoryTypes(CategoryTypes oCategoryTypes)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTCategoryTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oCategoryTypes.Title));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateCategoryTypes(CategoryTypes oCategoryTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATECategoryTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Title",DbType.String,oCategoryTypes.Title));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oCategoryTypes.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveCategoryTypes(CategoryTypes oCategoryTypes)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETECategoryTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,oCategoryTypes.Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveCategoryTypes(int Id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETECategoryTypes",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Id",DbType.Int32,Id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
